/*
    This is a set of libraries to assist in OpenGl and Other Applications
    Copyright (C) 2008  The Modular Engine Team

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

/// \file OpenglInterface.h
/// \brief Interface to Opengl using abstract functions

#ifndef OPENGLINTERFACE_H
#define OPENGLINTERFACE_H
#include "EngineCore.h"
#if WINDOWS
	#include <windows.h>
	#pragma comment( lib, "user32.lib" )
	#pragma comment( lib, "opengl32.lib" )
	#pragma comment( lib, "glu32.lib" )
	#pragma comment( lib, "Gdi32.lib" )
#endif
#include <gl/gl.h>
#include <gl/glu.h>
#if USING_GRAPHICS_INTERFACE_BASE
#include "GraphicsModule.h"
#endif
#include "math.h"
#include "ImageLoader.h"
#include <stack>

#undef CLASSDECL
#ifdef OPENGLINTERFACE
	#define CLASSDECL __declspec(dllexport)
#else
	#pragma comment( lib, "OpenglInterface.lib" )
	#define CLASSDECL __declspec(dllimport)
#endif

namespace ModularEngine
{

		/// Graphics Interface Options and States
	enum GI_OPTIONS
	{
		GI_TEXTURE = 0,
		GI_DEPTH_BUFFER_BIT,
		GI_COLOR_BUFFER_BIT,
		GI_POINTS,
		GI_LINES,
		GI_LINE_STRIP,
		GI_TRANGLES,
		GI_TRANGLE_STRIP,
		GI_TRANGLE_FAN,
		GI_QUADS,
		GI_QUAD_STRIP,
		GI_POLYGON
	};

	class CLASSDECL OpenglInterface: 
#if USING_GRAPHICS_INTERFACE_BASE
		public GraphicsInterfaceBase,
#endif
		public Singleton<OpenglInterface>
	{
	protected:
		std::list<TextureID> mlTextures;
	public:
		void init();

		std::stack<Vector2d> mvScissorPos;
		std::stack<Vector2d> mvScissorDims;
		
		/// Bind Textnum to current texture context
		void bindTexture( unsigned int nTex );

		/// Err... stuff 
		TextureID *loadTexture(const char *pTexturePath, const char *pMacro=0);

		void drawImage( const char *pTexturePath, Vector2d vPos );

		/// Draw Regular, untextured quad
		void drawQuad( Vector2d vPos, Vector2d vDims );
		/// Draw Textured Quad Using Entire Texture
		void drawQuad( unsigned int nTexture, Vector2d vPos, Vector2d vDims );
		/// Draw Textured Quad Using Texture Coordinates
		void drawQuad( unsigned int nTexture, Vector2d vTexCoords[2], Vector2d vPos, Vector2d vDims );

		/// Start Drawing

		/// iState refers to what we're drawing, be it lines, polygons etc.
		void startDrawing( unsigned int iState );

		/// Stop Drawing
		void stopDrawing();

		/// Enable something such as textures or lighting.
		void enable( unsigned int iState );

		/// Disable something...
		void disable( unsigned int iState );

		/// Set current texture
		void setTexture( unsigned int iTextureID );

		/// Translate GI_* Messages to GL_* Messages
		unsigned int translateMessages( unsigned int giMessage );

	};
}
#endif // IFNDEF OPENGLMODULE_H